﻿using System;
using System.Threading;

namespace CSharp_Sample
{
    public class Progress
    {
        public event EventHandler<ProgressEventArgs> ProgressUpdated;

        private readonly int _total;
        public Progress(int total)
        {
            this._total = total;
        }

        public void Start()
        {
            for (int i = 0;i<= _total; i++)
            {
                var args = new ProgressEventArgs
                {
                    Percentage = i,
                    Done = i==_total
                };
                Noticefy(args);
                Thread.Sleep(TimeSpan.FromMilliseconds(500));
            }
        }

        private void Noticefy(ProgressEventArgs args)
        {
            EventHandler<ProgressEventArgs> handler = ProgressUpdated;
            handler?.Invoke(this,args);
        }
    }
}